from __future__ import absolute_import
from os.path import join
from os import mkdir

from forest.registry import get_tool

def squashfilesystem(config):
    # package installtree into a ext4fs into a squash
    
    installtree = config.get_install_root()
    tempdir = config.get('tempdir')
    
    # 2GB sparse file compresses down to nothin'
    fssize = 2 * (1024*1024*1024)
    
    fssize = 500 * (1024*1024)
    
    squashfsdir = join(tempdir, 'squashfsdir')
    
    squashfsimage = join(tempdir, 'squashfs.img')
    
    ext3fsimage = join(squashfsdir, "ext3fs.img")
    
    mkdir(squashfsdir)
    
    get_tool('image.mkext4image')(installtree, ext3fsimage, label="Installer", size=fssize)
    # squash the live rootfs and clean up workdir
    #imgutils.mksquashfs(squashfsdir, squashfsimage, "xz", [])
    return squashfsimage, ext3fsimage
